{include 'header.tpl'}

<div class="contant">

    <div class="header">
        <div class="header_s">
            <span class="back"><a href="/index" ><i class="iconfont fan">&#xe679;</i></a></span>
            <span class="title">确认订单</span>
            <span class="add_ads">&nbsp;</span>
            <div class="clear"></div>
        </div>
    </div>

    <div class="submit_tlt"  onclick="javascript:window.location='/add/addlist?back=1'" >
        {if $user_address}
            <div class="section_area" id="section_area" >
                <div>
                    <p id="order_address" >{$user_address.province} {$user_address.city} {$user_address.county} {$user_address.address}</p>
                </div>
            </div>
            {else}
            <a href="/add/addlist?back=1">添加收货地址</a>
        {/if}

    </div>
    <div class="cart_cont">
        <div class="cart_conts">
            <div class="cart_conts_tlt">下单时间<span class="conts_tlt_ad">{$current_time}</span></div>
            {if $cart_list}
                {foreach from=$cart_list item=item name=foo}
                <div class="cart_contes_ct">
                    <div class="cart_lf"><img src="{Service_Attach::getInstance()->getThumbUrl($item.img2,150,150)}"/></div>
                    <div class="cart_rg">
                        <span> {$item.title} <em>￥{$item.price_new}</em></span>
                        <span>{if $item.spec_list}
                                {foreach from=$item.spec_list item=i name=foo}
                                    {$i.name}:{$i.value}
                                {/foreach}
                        {/if}
                        </span>
                        <div class="cart_rg_ad">
                            <span class="cart_rg_atlt">数量：</span>
                            <div class="cart_rg_add">
                                <span class="cart_add" gid="{$item.pid}" price="{$item.price_new}" ><a href="javascript:void(0)">+</a></span>
                                <span class="cart_number">{$item.cart_num}</span>
                                <span class="cart_crect" gid="{$item.pid}" price="{$item.price_new}" ><a href="javascript:void(0)">-</a></span>
                            </div>
                        </div>
                    </div>
                    <div class="del_f" gid="{$item.pid}" price="{$item.price_new}" num="{$item.cart_num}"   ><a href="javascript:void(0)">删除</a></div>
                </div>
                {/foreach}
            {/if}
            <div class="cart_contes_ct">
                <div class="cart_contes_tltl">由百度外卖统一配送服务<span class="conts_tlt_ad">￥{$money_ex.shipping}</span>
                </div>
                <!--<div class="cart_contes_tltl" style=" color:#9B9B9B;">由品牌商<em>美未央</em>进行派送</div>-->
            </div>

            <div class="cart_contes_ct">
                <div class="cart_contes_tltl">合计<span class="conts_tlt_ad"><em>￥<span id="price1">{$money_ex.price+$money_ex.shipping}</span></em></span>
                </div>
            </div>
        </div>

    </div>

    <div class="cart_cont">
        <div class="cart_conts_a">
            <div class="cart_conts_tlt_a">
                <span class="beizhu_tlt" >备注</span>
                <span class="beizhu_k"><input id="beizhu" placeholder="请备注您的口味和偏好，限140字以内" /></span>
            </div>
        </div>

    </div>


    <div class="cart_cont">
        <div class="cart_conts_a">
            <div class="cart_conts_tlt_b">￥<span id="price2">{$money_ex.price}</span>  +  ￥{{$money_ex.shipping}}配送费</div>
            <div class="cart_conts_tlt_b"><em >需付：￥<span id="price3">{$money_ex.paymoney}</span></em></div>
        </div>

    </div>
    <form  id="form_pay" action="/order/save" method="post">
        <input type="hidden" id="paymoney" name="paymoney" value="{$money_ex.paymoney}" />
        <input type="hidden" id="aid" name="aid" value="{if $user_address}{$user_address.auto_id}{else}0{/if}" />
        <input type="hidden" id="uid" name="uid" value="{$uid}" />
        <input type="hidden" id="shipping" name="shipping" value="{$money_ex.shipping}" />
        <input type="hidden" id="rshipping" name="rshipping" value="{$money_ex.rshipping}" />
        <input type="hidden" id="shop_id" name="shop_id" value="{if $shop_info}{$shop_info.id}{else}0{/if}" />
        <input type="hidden" id="pid" name="pid" value="{$money_ex.pid}" />
        <input type="hidden" id="remark" name="remark" value="" />
        <input type="hidden" id="dis" name="dis" value="{$money_ex.distance}" />

    </form>


    <div class="status_payment"><a class="topay"  href="javascript:void(0)">微信支付</a></div>
</div>
{literal}
<script>
    $(function(){
        $('.del_f').click(function(){
            var gid = $(this).attr('gid'),
                    price = $(this).attr('price'),
                    num=$(this).prev().find('.cart_number').text();
            var len=$(this).parent().parent().find('.cart_contes_ct').length;
            if(len==3){
                alert('产品不能为空');
                return false;
            }
            num=parseInt(num);
            var price1=$('#price1').text();
            var price2=$('#price2').text();
            var price3=$('#price3').text();
            var self = this;
            $.post('/order/update',{gid:gid,num:0},function(data){
                $(self).parent().remove();
                $('#price1').text(parseInt(price1)-(price*num));
                $('#price2').text(parseInt(price2)-(price*num));
                $('#price3').text(parseInt(price3)-(price*num));
                $('#paymoney').val(parseInt(price3)-(price*num));
            }, "json");
        });
        $('.cart_add').click(function(){
            var num = $(this).next('.cart_number').text();
            var gid = $(this).attr('gid');
            var self = this;
            var price = $(this).attr('price');
            var price1=$('#price1').text();
            var price2=$('#price2').text();
            var price3=$('#price3').text();
            //var paymoney=$('#paymoney').val();
            num = parseInt(num);
            num+=1;
            $.post('/order/update',{gid:gid,num:1},function(){
                $(self).next('.cart_number').text(num);
                $('#price1').text(parseInt(price1)+parseInt(price));
                $('#price2').text(parseInt(price2)+parseInt(price));
                $('#price3').text(parseInt(price3)+parseInt(price));
                $('#paymoney').val(parseInt(price3)+parseInt(price));
            });
        });
        $('.cart_crect').click(function(){
            var num = $(this).prev('.cart_number').text();
            var self = this;
            var gid = $(this).attr('gid');
            var price = $(this).attr('price');
            var price1=$('#price1').text();
            var price2=$('#price2').text();
            var price3=$('#price3').text();
            //var paymoney=$('#paymoney').val();
            num = parseInt(num);
           // console.log(num);
            if(num<=1){
                alert("不可为0");
                return;
            }
            num-=1;
            //console.log(num);

            $.post('/order/update',{gid:gid,num:-1},function(){
                $(self).prev('.cart_number').text(num);
                $('#price1').text(parseInt(price1)-parseInt(price));
                $('#price2').text(parseInt(price2)-parseInt(price));
                $('#price3').text(parseInt(price3)-parseInt(price));
                $('#paymoney').val(parseInt(price3)-parseInt(price));
            });
        });
        $('.topay').click(function(){
            if($("#aid").val()==0){
                alert('必须选配送地址');
                return;
            }
            $('#remark').val($('#beizhu').val());
            $('#form_pay').submit();
        });
    });
</script>
{/literal}
{include 'footer.tpl'}